﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Morus.Presentation
{
    public class PresenterBinding
    {
        private readonly Type _presenterType;
        private readonly Type _viewType;
        private readonly BindingMode _bindingMode;
        private readonly IEnumerable<IView> _viewInstances;

        [DebuggerStepThrough]
        public PresenterBinding(Type presenterType, Type viewType, BindingMode bindingMode, IEnumerable<IView> viewInstances)
        {
            _presenterType = presenterType;
            _viewType = viewType;
            _bindingMode = bindingMode;
            _viewInstances = viewInstances;
        }

        public Type PresenterType
        {
            [DebuggerStepThrough]
            get
            {
                return _presenterType;
            }
        }

        public Type ViewType
        {
            [DebuggerStepThrough]
            get
            {
                return _viewType;
            }
        }

        public BindingMode BindingMode
        {
            [DebuggerStepThrough]
            get
            {
                return _bindingMode;
            }
        }

        public IEnumerable<IView> ViewInstances
        {
            [DebuggerStepThrough]
            get
            {
                return _viewInstances;
            }
        }

        public override bool Equals(object obj)
        {
            var target = obj as PresenterBinding;
            if (target == null)
            {
                return false;
            }

            return
                PresenterType == target.PresenterType &&
                ViewType == target.ViewType &&
                BindingMode == target.BindingMode &&
                ViewInstances.SetEqual(target.ViewInstances);
        }

        public override int GetHashCode()
        {
            return
                PresenterType.GetHashCode() |
                ViewType.GetHashCode() |
                BindingMode.GetHashCode() |
                ViewInstances.GetHashCode();
        }
    }
}
